<template>
  <div class="box" v-loading="boxLoading">
    <el-row>
      <el-col :span="3" :offset="1">
        {{ title }}
      </el-col>
      <el-col :span="2" v-if="type != 'all'">
        本周新增<i class="number">{{ weekCountNum }}</i>&nbsp;位
      </el-col>
      <el-col :span="2" v-if="type != 'all'">
        本月新增<i class="number">{{ monthCountNum }}</i>&nbsp;位
      </el-col>
      <el-col :span="2" v-if="type != 'all'">
        共新增<i class="number">{{ allCountNum }}</i>&nbsp;位
      </el-col>
      <el-col :span="2" v-if="type == 'all'">
        共<i class="number">{{ allCuCountNum }}</i>&nbsp;位
      </el-col>
    </el-row>
  </div>
</template>

<script>

import {getAddCount as addCount, getAllCount} from "@/api/system/customer";
import {visitCount} from "@/api/system/visitInfo";
import {getAddCount as propertyAddCount, getAllCount as getPropertyAllCount} from "@/api/system/property_customer";
import {visitCount as propertyVisitCount} from "@/api/system/property_visitInfo";
import {successCount} from "@/api/system/contract";

export default {
  name: "MyBox",
  data() {
    return {
      allCountNum: null,
      weekCountNum: null,
      monthCountNum: null,
      allCuCountNum: null,
      boxLoading: false
    }
  },
  props: ['type', 'isSalePage', 'title', 'page'],
  created() {
    this.initByType();
  },
  methods: {
    //获取新增客户统计
    getAddCount(isSalePage) {
      this.boxLoading = true;
      addCount({type: 'all', isSalePage: isSalePage}).then(
        res => {
          this.allCountNum = res.data;
        }
      )
      addCount({type: 'week', isSalePage: isSalePage}).then(
        res => {
          this.weekCountNum = res.data;
        }
      )
      addCount({type: 'month', isSalePage: isSalePage}).then(
        res => {
          this.monthCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    propertyAddCount(isSalePage) {
      this.boxLoading = true;
      propertyAddCount({type: 'all', isSalePage: isSalePage}).then(
        res => {
          this.allCountNum = res.data;
        }
      )
      propertyAddCount({type: 'week', isSalePage: isSalePage}).then(
        res => {
          this.weekCountNum = res.data;
        }
      )
      propertyAddCount({type: 'month', isSalePage: isSalePage}).then(
        res => {
          this.monthCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    //获取跟进客户统计
    getPropertyVisitCount() {
      this.boxLoading = true;
      propertyVisitCount({type: 'all'}).then(
        res => {
          this.allCountNum = res.data;
        }
      )
      propertyVisitCount({type: 'week'}).then(
        res => {
          this.weekCountNum = res.data;
        }
      )
      propertyVisitCount({type: 'month'}).then(
        res => {
          this.monthCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    //获取跟进客户统计
    getVisitCount() {
      this.boxLoading = true;
      visitCount({type: 'all'}).then(
        res => {
          this.allCountNum = res.data;
        }
      )
      visitCount({type: 'week'}).then(
        res => {
          this.weekCountNum = res.data;
        }
      )
      visitCount({type: 'month'}).then(
        res => {
          this.monthCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    //获取成交客户统计
    getSuccessCount(isSalePage) {
      this.boxLoading = true;
      successCount({type: 'all', isSalePage: isSalePage}).then(
        res => {
          this.allCountNum = res.data;
        }
      )
      successCount({type: 'week', isSalePage: isSalePage}).then(
        res => {
          this.weekCountNum = res.data;
        }
      )
      successCount({type: 'month', isSalePage: isSalePage}).then(
        res => {
          this.monthCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    //获取全部
    getAllCountNum() {
      this.boxLoading = true;
      getAllCount().then(
        res => {
          this.allCuCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    //获取全部
    getPropertyAllCount() {
      this.boxLoading = true;
      getPropertyAllCount().then(
        res => {
          this.allCuCountNum = res.data;
          this.boxLoading = false;
        }
      )
    },
    //通过type发送不同请求
    initByType() {
      if (this.page == 'property') {
        if (this.type == 'add') {
          this.propertyAddCount(this.isSalePage);
        } else if (this.type == 'visit') {
          this.getPropertyVisitCount(this.isSalePage);
        } else if (this.type == 'all') {
          this.getPropertyAllCount();
        }
      } else {
        if (this.type == 'add') {
          this.getAddCount(this.isSalePage);
        } else if (this.type == 'success') {
          this.getSuccessCount(this.isSalePage);
        } else if (this.type == 'all') {
          this.getAllCountNum();
        } else if (this.type == 'visit') {
          this.getVisitCount();
        }
      }
    }
  },
}
</script>

<style scoped>
.box .number {
  color: #409EFF;
}

.box {
  color: #303133;
}

.el-col {
  height: 25px;
}
</style>
